package com.loop.unclelend.pro

import com.loop.unclelend.MyApplication
import com.loop.unclelend.base.BaseFragment
import com.loop.unclelend.network.IHttpCallback
import com.loop.unclelend.utils.event.UncleEventData
import com.loop.unclelend.utils.event.UncleSubscriber
import org.json.JSONObject

/**
 * UncleLend
 * @Author wwdeng
 * @CreateTime: 2024/9/3 15:58
 * @Annotation：
 */
abstract class ProFragment: BaseFragment(), UncleSubscriber,IProView {

    override fun getAct(): ProActivity {
        return context as ProActivity
    }

    override fun onStart() {
        super.onStart()
        MyApplication.app.publisher.register(this)
    }

    /**
     * 客服
     */
    fun showUncleKefuDialog(eventRemark: String = ""){
        getAct().showUncleKefuDialog(eventRemark)
    }

    /**
     * 错误提示
     */
    fun showErrorTipsDialog(tips: String,eventRemark: String = ""){
        getAct().showErrorTipsDialog(tips,eventRemark)
    }

    /**
     * post
     */
    fun doPostAction(httpUrl: String, params: JSONObject, callback: IHttpCallback){
        getAct().doPostAction(httpUrl, params, callback)
    }

    /**
     * 发送事件通知
     */
    fun publishEventData(eventData: UncleEventData){
        MyApplication.app.publisher.publish(eventData)
    }

    /**
     * 处理订阅事件
     */
    override fun onUncleEvent(event: UncleEventData) {

    }

    override fun onDestroy() {
        super.onDestroy()
        MyApplication.app.publisher.detach(this)
    }
}